import global from '@/utils/global'
import http from '@/utils/request'

export function getList(searchForm) {
  return http({
    url: http.adornUrl(global.upms + '/role/list'),
    headers: { // application/json; charset=utf-8 //application/x-www-form-urlencoded; charset=utf-8
      'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
    },
    method: 'post',
    data: http.adornData({
      'name': searchForm.name === '' ? null : searchForm.name,
      'code': searchForm.code === '' ? null : searchForm.code,
      'status': searchForm.status === '' ? null : searchForm.status,
      'begin': searchForm.beginDate === '' ? null : searchForm.beginDate,
      'end': searchForm.endDate === '' ? null : searchForm.endDate
    }, true, 'form')
  })
}

export function add(modelForm) {
  return http({
    url: http.adornUrl(global.upms + '/role'),
    method: 'post',
    data: http.adornData({
      'name': modelForm.name,
      'code': modelForm.code,
      'description': modelForm.description,
      'sort': modelForm.sort === null ? 99 : modelForm.sort,
      'status': modelForm.status
    })
  })
}

export function update(modelForm) {
  return http({
    url: http.adornUrl(global.upms + '/role/' + modelForm.id),
    method: 'patch',
    data: http.adornData({
      'id': modelForm.id,
      'name': modelForm.name,
      'code': modelForm.code,
      'description': modelForm.description,
      'sort': modelForm.sort === null ? 99 : modelForm.sort,
      'status': modelForm.status
    })
  })
}

export function deleteOne(id) {
  return http({
    url: http.adornUrl(global.upms + '/role/batch/' + id),
    method: 'delete'
  })
}

export function deleteBatch(ids) {
  return http({
    url: http.adornUrl(global.upms + '/role/delete/batches'),
    headers: { // application/json; charset=utf-8 //application/x-www-form-urlencoded; charset=utf-8
      'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
    },
    method: 'post',
    data: http.adornData({
      'ids': ids
    }, true, 'form')
  })
}
